%**************************************************************************
%
%           "Endogenous Liquidity and Capital Reallocation"
%      Cui, W., Wright, R., & Zhu, Y. (2024), Journal of Political Economy
%                       Last Modified: Feb 2024.  
%
%**************************************************************************

%%%% Computing steady state and comparative statics with interest rate/inflation

clc; clear; close all; format short



%% 1. --------------------    Initialization   ----------------------------

%%%% This step is important to initiate if parameters were not saved.
%Main_iid_calibration


%%%% Load parameters from calibration
load param_calibrated; 
load eqm_calibrated;

variable_x          = '\iota'; 
range               = [0, 0.2]; % real rate is fixed in steady state; changing iota is equivalent to changing inflation
THETA_grid          = [0.45, 0.50, 0.55];
THETA_grid_legend   = {'0.45','0.50','0.55'};
colors              = [0, 0, 1; 1, 0, 0; 0.9, 0.6, 0.2];
line_style          = {'--';'-';'-.'};

%%%% Options value to be used in fsolve
options                     = optimset('Display','off'); 
options.OptimalityTolerance = 1e-6; 
options.StepTolerance       = 1e-6;
options.MaxIter             = 1000000; 
options.MaxFunEvals         = 1000000; 
options.FunctionTolerance   = 1e-6;


%% 2. ----------------   Now, running comparative statics -----------------

disp('***************>      Comparative Statics     <*********************')

%%%% inflation_ = 1 means we plot inflation instead of nominal interest rate
inflation_  = 0; 
plotting_   = 1;

%%%% Comparative statics of our model (model #6)
par_ini    = par_calibrated;
do_model_6

%%%% Save variables as functions of nominal interest rate 
%%%% for medium and long-run analysis; 
%%%% Interest rate will be translated to inflation in other computation
ItoOutput_model_6 = Inv_model_6./(Output_model_6 - par.G);
CtoOutput_model_6 = Consumption_model_6./(Output_model_6 - par.G);

for i = 1:3
    Table_model{i} =[x_grid(id1, i), ItoOutput_model_6(id1,i), CtoOutput_model_6(id1,i),...
        Hours_model_6(id1,i), R_ratio_model_6(id1,i), P_share_model_6(id1,i)];

end
save('model_long_run_raw','Table_model')

